import React, { Component } from 'react';
import { isFileExist } from '../util/commons-tools';
class Video extends Component {
 
    componentDidMount() {
        this.interval = setTimeout(this.onEnded, this.props.media.playTime * 1000)
    }

    componentWillReceiveProps(nextProps) {
        this.interval = setTimeout(this.onEnded, nextProps.media.playTime * 1000)
    }

    componentWillUnmount() {
        clearInterval(this.interval)
    }

    onEnded=()=> {
        this.props.startNextMedia()
    }

    render() {
        console.log(this.props.media && this.props.media.Name,"imgsrc")
        let url = this.props.media && this.props.media.Name.split("/")
        url = `downloadFile/${url[url.length - 1]}`
        return (
            <div >
                <img style={{
                    "width": "100%",
                    "height": "100%",
                }} src={isFileExist(url) ? url : this.props.media.Name} alt='' />
            </div>);
    }
}

export default Video;
